package intant.enums.test;

import com.alibaba.fastjson.JSONObject;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Map;

public class MapEnumProTestCase {

    @Test
    public void testRespJson() {
        Assertions.assertEquals(RespCode.SYSTEM_ERROR.getMapVo().getClass(), JSONObject.class);
    }


    enum RespCode implements MapEnum<Integer> {
        SYSTEM_ERROR(-1, "系统错误", 500),
        PARAM_ERROR(-2, "参数错误", 400),
        RESOURCE_NOT_FOUND(-3, "资源不存在", 404),
        BUSINESS_ERROR(-4, "业务错误", 200),
        SUCCESS(0, "处理成功", 200)
        ;

        private final Integer code;
        private final String desc;
        private final Integer respStatus;

        RespCode(Integer code, String desc, Integer respStatus) {
            this.code = code;
            this.desc = desc;
            this.respStatus = respStatus;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @Override
        public String getDesc() {
            return desc;
        }


        @Override
        public Map<String, Object> getInitMap() {
            return new JSONObject(4, true);
        }

        @Override
        public void extendVo(Map<String, Object> vo) {
            vo.put("status", respStatus);
        }

        @Override
        public String getDescKey() {
            return "msg";
        }


    }


}
